<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

/**
 * Description of member_model
 *
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Admin_member_model extends CI_Model {

	function __construct() {
		parent::__construct();
		log_message('debug', 'Model Initialized');
	}

	function get_member($mem_id){
		if($mem_id){
			$sql="select * from member where id=$mem_id and status=51 ";
			$query = $this->db->query($sql);
			if ($query->row())
				return $query->row();
			else
				return false;
		}else{
			return false;
		}
	}
	 


	/*function get_members($status = 1) {
		if (!$this->db->table_exists('member_master')) {
			return FALSE;
		}
		$sql = "select * from member_master where status=$status order by id";
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
*/
	function get_members($status=1,$num=NULL, $offset=NULL) {
		$subcond = "where status=$status";
		$limit = "";
		if (isset($num) && isset($offset))
			$limit = " order by (id) desc limit $offset, $num";
		$sql = "select * from member " . $subcond . $limit;
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
	
	function get_inactive_members($status=51,$num=NULL, $offset=NULL) {
		$subcond = "where status=$status";
		$limit = "";
		if (isset($num) && isset($offset))
			$limit = " order by (id) desc limit $offset, $num";
		$sql = "select * from member " . $subcond . $limit;
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}

	function search($search=null){
		$sql = "Select * from member where name like '$search%' order by id desc";
		$query = $this->db->query($sql);
		$result = $query->result();
		if($result){
			return $query->result();
		}else{
			return false;
		}
	}
	function change_status($id, $status) {
		if ($status == 1) {
			$sql = "update member set status=51 where id=$id";
		}
		if ($status == 51) {
			$sql = "update member set status=1 where id=$id";
		}
		$this->db->query($sql);
	}
	/*
	 function change_status($status=NUll, $id=NULL)
	 {

	$sql="update member_master set status=$status where id=$id";
	$this->db->query($sql);
	}
	*/
	function delete($id=NULL)
	{
		$sql="delete from member where id=$id";
		$this->db->query($sql);
	}

	function get_member_details($id=NULL) {
		$sql = "select * from member where id=$id";
		$query = $this->db->query($sql);
		$row = $query->row();
		return $row;
	}


}